package gaml.java.serializer.primitive;

import gaml.error.GamlException;
import gaml.java.ClassSerializer;
import gaml.yaml.ScalarNode;
import gaml.yaml.YamlNode;
import gaml.yaml.ahchor.YamlAnchorCodeStore;
import gaml.yaml.ahchor.YamlAnchorObjectStore;


/**
 * make a node from integer
 * parse integer from node
 * @author shnireck
 *
 */
public class IntegerSerializer implements ClassSerializer <Integer> {
	
	@Override
	public Class <Integer> getObjectClass () { return Integer.class; }

	@Override
	public boolean noAnchor () { return true; }
	
	@Override
	public Integer restore (YamlNode node, Integer object, YamlAnchorCodeStore anchors) { return (null == node.getValue () ? 0 : Integer.parseInt (node.getValue ())); }

	@Override
	public YamlNode serialize (YamlNode node, Integer obj, YamlAnchorObjectStore anchors) { return new ScalarNode (node.getParent ()).setValue (obj.toString ()); }

	@Override
	public YamlNode createNode (YamlNode parent) { return new ScalarNode (parent); }

	@Override
	public Integer createObject () throws GamlException { return null; }
}